< previous page page_470 next page >

Page 470
Now save and run the project. Select an entire record by clicking the left margin of the grid. This highlights all the columns in the row. To delete the record, press the Delete key or Ctrl+X. When the message pops up asking you to confirm the delete, answer No to cancel. (See Figure 12.15.)
0470-01.jpg
Figure 12.15.
Attempting to delete
a record from the grid.
Column-Level Events
Several column-level events are available for the data grid. The following are only two of them:
·BeforeColUpdate: This event occurs before the column is updated with any changes made by the user. Use this event to perform data validation before the update occurs.
·AfterColUpdate: This event occurs after the column has been updated with user changes. Use this event to perform other duties after the value of the column has been updated.
Note.gif
Refer to the Visual Basic 5 documentation for a list of all the events associated with the DBGrid control.

These events work just like the BeforeUpdate and AfterUpdate events seen earlier. However, instead of occurring whenever the record value is updated, the BeforeColUpdate and AfterColUpdate events occur whenever a column value is changed. This gives you the ability to perform field-level validation within the data grid.
Add some code in the BeforeColUpdate event to force the user to confirm the update of a column. Open the DBGrid.BeforeColUpdate event and enter the code in Listing 12.4.
Type.gifListing 12.4. Code to request confirmation on column updates.
Private Sub DBGrid1_BeforeColUpdate(ByVal ColIndex As Integer,
_ OldValue As Variant, Cancel As Integer)
    '
    ' ask user for confirmation
    '

 
< previous page page_470 next page >

If you like this book, buy it!